package d1_ip;

import java.io.IOException;
import java.net.InetAddress;

/**
 * 2024/6/28 掌握InetAddress类的使用 Cjj 12:36
 */
public class IntAddressTest {
    public static void main(String[] args) throws IOException {
        //1.获取本机IP地址对象的
        InetAddress ip1=InetAddress.getLocalHost();
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getAddress());

        //2.获取指定IP或者域名的IP地址对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());

        //ping www.baidu.com
        System.out.println(ip2.isReachable(6000));
        
    }
}
